<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>menubuttonrenderer.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_menubuttonrenderer.js.html">menubuttonrenderer.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2008 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Renderer for {@link goog.ui.MenuButton}s and subclasses.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.ui.MenuButtonRenderer&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.dom&#39;);
<a name="line23"></a>goog.require(&#39;goog.style&#39;);
<a name="line24"></a>goog.require(&#39;goog.ui.CustomButtonRenderer&#39;);
<a name="line25"></a>goog.require(&#39;goog.ui.INLINE_BLOCK_CLASSNAME&#39;);
<a name="line26"></a>goog.require(&#39;goog.ui.Menu&#39;);
<a name="line27"></a>goog.require(&#39;goog.ui.MenuRenderer&#39;);
<a name="line28"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line29"></a>
<a name="line30"></a>
<a name="line31"></a>/**
<a name="line32"></a> * Renderer for {@link goog.ui.MenuButton}s.  This implementation overrides
<a name="line33"></a> * {@link goog.ui.CustomButtonRenderer#createButton} to create a separate
<a name="line34"></a> * caption and dropdown element.
<a name="line35"></a> * @constructor
<a name="line36"></a> * @extends {goog.ui.CustomButtonRenderer}
<a name="line37"></a> */
<a name="line38"></a>goog.ui.MenuButtonRenderer = function() {
<a name="line39"></a>  goog.ui.CustomButtonRenderer.call(this);
<a name="line40"></a>};
<a name="line41"></a>goog.inherits(goog.ui.MenuButtonRenderer, goog.ui.CustomButtonRenderer);
<a name="line42"></a>goog.addSingletonGetter(goog.ui.MenuButtonRenderer);
<a name="line43"></a>
<a name="line44"></a>
<a name="line45"></a>/**
<a name="line46"></a> * Default CSS class to be applied to the root element of components rendered
<a name="line47"></a> * by this renderer.
<a name="line48"></a> * @type {string}
<a name="line49"></a> */
<a name="line50"></a>goog.ui.MenuButtonRenderer.CSS_CLASS = goog.getCssName(&#39;goog-menu-button&#39;);
<a name="line51"></a>
<a name="line52"></a>
<a name="line53"></a>/**
<a name="line54"></a> * A property to denote content elements that have been wrapped in an extra
<a name="line55"></a> * div to work around FF2/RTL bugs.
<a name="line56"></a> * @type {string}
<a name="line57"></a> * @private
<a name="line58"></a> */
<a name="line59"></a>goog.ui.MenuButtonRenderer.WRAPPER_PROP_ = &#39;__goog_wrapper_div&#39;;
<a name="line60"></a>
<a name="line61"></a>
<a name="line62"></a>if (goog.userAgent.GECKO) {
<a name="line63"></a>  /**
<a name="line64"></a>   * Takes the menubutton&#39;s root element, and sets its content to the given
<a name="line65"></a>   * text caption or DOM structure. Because the DOM structure of this button is
<a name="line66"></a>   * conditional based on whether we need to work around FF2/RTL bugs, we
<a name="line67"></a>   * override the default implementation to take this into account.
<a name="line68"></a>   * @param {Element} element The control&#39;s root element.
<a name="line69"></a>   * @param {goog.ui.ControlContent} content Text caption or DOM
<a name="line70"></a>   *     structure to be set as the control&#39;s content.
<a name="line71"></a>   * @override
<a name="line72"></a>   */
<a name="line73"></a>  goog.ui.MenuButtonRenderer.prototype.setContent = function(element,
<a name="line74"></a>      content) {
<a name="line75"></a>    var caption =
<a name="line76"></a>        goog.ui.MenuButtonRenderer.superClass_.getContentElement.call(this,
<a name="line77"></a>            /** @type {Element} */ (element &amp;&amp; element.firstChild));
<a name="line78"></a>    if (caption) {
<a name="line79"></a>      goog.dom.replaceNode(
<a name="line80"></a>          this.createCaption(content, goog.dom.getDomHelper(element)),
<a name="line81"></a>          caption);
<a name="line82"></a>    }
<a name="line83"></a>  };
<a name="line84"></a>} // end goog.userAgent.GECKO
<a name="line85"></a>
<a name="line86"></a>
<a name="line87"></a>/**
<a name="line88"></a> * Takes the button&#39;s root element and returns the parent element of the
<a name="line89"></a> * button&#39;s contents.  Overrides the superclass implementation by taking
<a name="line90"></a> * the nested DIV structure of menu buttons into account.
<a name="line91"></a> * @param {Element} element Root element of the button whose content element
<a name="line92"></a> *     is to be returned.
<a name="line93"></a> * @return {Element} The button&#39;s content element.
<a name="line94"></a> */
<a name="line95"></a>goog.ui.MenuButtonRenderer.prototype.getContentElement = function(element) {
<a name="line96"></a>  var content =
<a name="line97"></a>      goog.ui.MenuButtonRenderer.superClass_.getContentElement.call(this,
<a name="line98"></a>          /** @type {Element} */ (element &amp;&amp; element.firstChild));
<a name="line99"></a>  if (goog.userAgent.GECKO &amp;&amp; content &amp;&amp;
<a name="line100"></a>      content[goog.ui.MenuButtonRenderer.WRAPPER_PROP_]) {
<a name="line101"></a>    content = /** @type {Element} */ (content.firstChild);
<a name="line102"></a>  }
<a name="line103"></a>  return content;
<a name="line104"></a>};
<a name="line105"></a>
<a name="line106"></a>
<a name="line107"></a>/**
<a name="line108"></a> * Takes an element, decorates it with the menu button control, and returns
<a name="line109"></a> * the element.  Overrides {@link goog.ui.CustomButtonRenderer#decorate} by
<a name="line110"></a> * looking for a child element that can be decorated by a menu, and if it
<a name="line111"></a> * finds one, decorates it and attaches it to the menu button.
<a name="line112"></a> * @param {goog.ui.MenuButton} button Menu button to decorate the element.
<a name="line113"></a> * @param {Element} element Element to decorate.
<a name="line114"></a> * @return {Element} Decorated element.
<a name="line115"></a> */
<a name="line116"></a>goog.ui.MenuButtonRenderer.prototype.decorate = function(button, element) {
<a name="line117"></a>  // TODO:  Add more robust support for subclasses of goog.ui.Menu.
<a name="line118"></a>  var menuElem = goog.dom.$$(&#39;*&#39;, goog.ui.MenuRenderer.CSS_CLASS, element)[0];
<a name="line119"></a>  if (menuElem) {
<a name="line120"></a>    // Move the menu element directly under the body (but hide it first to
<a name="line121"></a>    // prevent flicker; see bug 1089244).
<a name="line122"></a>    goog.style.showElement(menuElem, false);
<a name="line123"></a>    goog.dom.appendChild(goog.dom.getOwnerDocument(menuElem).body, menuElem);
<a name="line124"></a>
<a name="line125"></a>    // Decorate the menu and attach it to the button.
<a name="line126"></a>    var menu = new goog.ui.Menu();
<a name="line127"></a>    menu.decorate(menuElem);
<a name="line128"></a>    button.setMenu(menu);
<a name="line129"></a>  }
<a name="line130"></a>
<a name="line131"></a>  // Let the superclass do the rest.
<a name="line132"></a>  return goog.ui.MenuButtonRenderer.superClass_.decorate.call(this, button,
<a name="line133"></a>      element);
<a name="line134"></a>};
<a name="line135"></a>
<a name="line136"></a>
<a name="line137"></a>/**
<a name="line138"></a> * Takes a text caption or existing DOM structure, and returns the content and
<a name="line139"></a> * a dropdown arrow element wrapped in a pseudo-rounded-corner box.  Creates
<a name="line140"></a> * the following DOM structure:
<a name="line141"></a> *    &lt;div class=&quot;goog-inline-block goog-menu-button-outer-box&quot;&gt;
<a name="line142"></a> *      &lt;div class=&quot;goog-inline-block goog-menu-button-inner-box&quot;&gt;
<a name="line143"></a> *        &lt;div class=&quot;goog-inline-block goog-menu-button-caption&quot;&gt;
<a name="line144"></a> *          Contents...
<a name="line145"></a> *        &lt;/div&gt;
<a name="line146"></a> *        &lt;div class=&quot;goog-inline-block goog-menu-button-dropdown&quot;&gt;
<a name="line147"></a> *          &amp;nbsp;
<a name="line148"></a> *        &lt;/div&gt;
<a name="line149"></a> *      &lt;/div&gt;
<a name="line150"></a> *    &lt;/div&gt;
<a name="line151"></a> * @param {goog.ui.ControlContent} content Text caption or DOM structure
<a name="line152"></a> *     to wrap in a box.
<a name="line153"></a> * @param {goog.dom.DomHelper} dom DOM helper, used for document interaction.
<a name="line154"></a> * @return {Element} Pseudo-rounded-corner box containing the content.
<a name="line155"></a> */
<a name="line156"></a>goog.ui.MenuButtonRenderer.prototype.createButton = function(content, dom) {
<a name="line157"></a>  return goog.ui.MenuButtonRenderer.superClass_.createButton.call(this,
<a name="line158"></a>      [this.createCaption(content, dom), this.createDropdown(dom)], dom);
<a name="line159"></a>};
<a name="line160"></a>
<a name="line161"></a>
<a name="line162"></a>/**
<a name="line163"></a> * Takes a text caption or existing DOM structure, and returns it wrapped in
<a name="line164"></a> * an appropriately-styled DIV.  Creates the following DOM structure:
<a name="line165"></a> *    &lt;div class=&quot;goog-inline-block goog-menu-button-caption&quot;&gt;
<a name="line166"></a> *      Contents...
<a name="line167"></a> *    &lt;/div&gt;
<a name="line168"></a> * @param {goog.ui.ControlContent} content Text caption or DOM structure
<a name="line169"></a> *     to wrap in a box.
<a name="line170"></a> * @param {goog.dom.DomHelper} dom DOM helper, used for document interaction.
<a name="line171"></a> * @return {Element} Caption element.
<a name="line172"></a> */
<a name="line173"></a>goog.ui.MenuButtonRenderer.prototype.createCaption = function(content, dom) {
<a name="line174"></a>  return goog.ui.MenuButtonRenderer.wrapCaption(
<a name="line175"></a>      content, this.getCssClass(), dom);
<a name="line176"></a>};
<a name="line177"></a>
<a name="line178"></a>
<a name="line179"></a>/**
<a name="line180"></a> * Takes a text caption or existing DOM structure, and returns it wrapped in
<a name="line181"></a> * an appropriately-styled DIV.  Creates the following DOM structure:
<a name="line182"></a> *    &lt;div class=&quot;goog-inline-block goog-menu-button-caption&quot;&gt;
<a name="line183"></a> *      Contents...
<a name="line184"></a> *    &lt;/div&gt;
<a name="line185"></a> * @param {goog.ui.ControlContent} content Text caption or DOM structure
<a name="line186"></a> *     to wrap in a box.
<a name="line187"></a> * @param {string} cssClass The CSS class for the renderer.
<a name="line188"></a> * @param {goog.dom.DomHelper} dom DOM helper, used for document interaction.
<a name="line189"></a> * @return {Element} Caption element.
<a name="line190"></a> */
<a name="line191"></a>goog.ui.MenuButtonRenderer.wrapCaption = function(content, cssClass, dom) {
<a name="line192"></a>  return dom.createDom(
<a name="line193"></a>      &#39;div&#39;,
<a name="line194"></a>      goog.ui.INLINE_BLOCK_CLASSNAME + &#39; &#39; +
<a name="line195"></a>          goog.getCssName(cssClass, &#39;caption&#39;),
<a name="line196"></a>      content);
<a name="line197"></a>};
<a name="line198"></a>
<a name="line199"></a>
<a name="line200"></a>/**
<a name="line201"></a> * Returns an appropriately-styled DIV containing a dropdown arrow element.
<a name="line202"></a> * Creates the following DOM structure:
<a name="line203"></a> *    &lt;div class=&quot;goog-inline-block goog-menu-button-dropdown&quot;&gt;
<a name="line204"></a> *      &amp;nbsp;
<a name="line205"></a> *    &lt;/div&gt;
<a name="line206"></a> * @param {goog.dom.DomHelper} dom DOM helper, used for document interaction.
<a name="line207"></a> * @return {Element} Dropdown element.
<a name="line208"></a> */
<a name="line209"></a>goog.ui.MenuButtonRenderer.prototype.createDropdown = function(dom) {
<a name="line210"></a>  // 00A0 is &amp;nbsp;
<a name="line211"></a>  return dom.createDom(&#39;div&#39;,
<a name="line212"></a>      goog.ui.INLINE_BLOCK_CLASSNAME + &#39; &#39; +
<a name="line213"></a>      goog.getCssName(this.getCssClass(), &#39;dropdown&#39;), &#39;\u00A0&#39;);
<a name="line214"></a>};
<a name="line215"></a>
<a name="line216"></a>
<a name="line217"></a>/**
<a name="line218"></a> * Returns the CSS class to be applied to the root element of components
<a name="line219"></a> * rendered using this renderer.
<a name="line220"></a> * @return {string} Renderer-specific CSS class.
<a name="line221"></a> */
<a name="line222"></a>goog.ui.MenuButtonRenderer.prototype.getCssClass = function() {
<a name="line223"></a>  return goog.ui.MenuButtonRenderer.CSS_CLASS;
<a name="line224"></a>};
</pre>


</body>
</html>
